<template>
  <!-- 法规平台 -->
  <div class="app-container">
    <!-- <h1>法规平台</h1> -->
    <el-button
      type="primary"
      @click="addEeleases"
      v-hasPermi="['financial:voucherRatio:add']"
      >新增发放</el-button
    >
    <div class="boxlaw">
      <ComTable
        @handleCurrentChange="CurrentPageChangeFn"
        @handleSizeChange="currentPageSizeChangeFn"
        :key="random"
        :list="tableList"
        :modes="tableModes"
        :config="{ border: true, loading }"
        :pagination="{ total: paging.total, pageNum: paging.pageNum }"
      >
        <el-table-column #default="{ row }" align="left">
          <template>
            <el-button
              v-hasPermi="[
                'financial:voucherRatio:edit',
                'financial:voucherRatio:getInfo',
              ]"
              @click="editFn(row)"
              plain
              size="mini"
              type="primary"
              >修改</el-button
            >

            <el-button
              @click="deleteFn(row)"
              v-hasPermi="['financial:voucherRatio:remove']"
              plain
              size="mini"
              type="primary"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </ComTable>
      <AddAndEdit
        @EventFretchList="getVoucherRatioListFn"
        ref="AddAndEdit"
        :selectOption="selectOption"
        :dialogVisible.sync="dialogVisible"
      ></AddAndEdit>
    </div>
  </div>
</template>

<script>
import ComForm from "../../../components/comForm.vue";

import {
  getVoucherRatioListApi,
  getVoucherRatioStatusApi,
} from "@/wss/api/financial/voucherRatio.js";
import ComTable from "../../../components/comTable.vue";

import AddAndEdit from "./addAndEdit.vue";
export default {
  name: "laws",
  dicts: ["sys_normal_disable"],
  components: { ComForm, ComTable, AddAndEdit },

  data() {
    return {
      dialogVisible: false,
      initSelectValue: "",
      selectOption: [],
      // 加载
      loading: false,
      paging: { pageNum: 1, pageSize: 10, status: "", total: 10 },
      // 切换筛选状态，不更新bug修复
      random: "",
      // 当前筛选的状态
      currentSelect: "",
      options: {
        value: "",
        title: "快速筛选",
        list: [
          {
            value: "",
            label: "全部",
          },
          {
            value: "0",
            label: "待编辑",
          },
          {
            value: "1",
            label: "审核中",
          },
          {
            value: "2",
            label: "审核失败",
          },

          {
            value: "4",
            label: "上架",
          },
          {
            value: "5",
            label: "下架",
          },
        ],
      },
      // 动态生成下拉列表的筛选条件
      dynamicFilter: {},
      // 表格的数据
      tableList: [],
      // 表格的列字段
      tableModes: [
        {
          label: "角色",
          mode: "postionName",
        },
        {
          label: "职等",
          mode: "level",
          showOverflowTooltip: true,
        },
        {
          label: "配比比例（%）",
          mode: "ratio",
          effectiveStatus: true,
          width: 100,
          align: "center",
          isShowTag: true,
        },
        {
          label: "创建时间",
          mode: "createTime",
        },
      ],
      comForm: {
        modes: [
          {
            placeholder: "请选择日期",
            formType: "select",

            mode: "effectiveStatus",
            label: "月份",
            value: "",
            select: [],
          },
        ],
      },
    };
  },

  mounted() {
    this.getVoucherRatioListFn(this.paging);
  },
  methods: {
    // 重设函数
    resetFn() {
      this.initSelectValue = "";
      this.romdom = Math.random();
      this.options.value = "";
      this.paging.status = "";
      console.log(this.paging, "重设");
    },
    // 当前页发生改变时候
    CurrentPageChangeFn(pageNUm) {
      this.paging.pageNum = pageNUm;
      this.getVoucherRatioListFn(this.paging);
    },
    // 页容量发生改变时候
    currentPageSizeChangeFn(pageSize) {
      this.paging.pageSize = pageSize;
      this.getVoucherRatioListFn(this.paging);
    },
    // 筛选数据
    queryFn(arr) {
      arr.forEach((item) => {
        for (const key in item) {
          this.paging[key] = item[key];
        }
      });
      this.currentSelect = this.initSelectValue;
      console.log(this.paging, "查询");
      this.paging.pageNum = 1;
      this.getVoucherRatioListFn(this.paging);
    },
    // 获取列表数据
    async getVoucherRatioListFn(pagination = null) {
      this.loading = true;
      let date,
        result = await getVoucherRatioListApi(pagination);
      this.selectOption = result.rows;
      console.table(this.selectOption);
      console.log(result, "问金");
      if (result.code == 200) {
        this.tableList = JSON.parse(JSON.stringify(result.rows));
        this.paging.total = result.total;
        console.log(result.rows);
        // 把后端放回的字段变成下拉筛选字段
        result.rows.forEach((item, index) => {
          console.log(item);
        });

        this.loading = false;
      }
    },
    // 打开新增发放对话框
    addEeleases() {
      console.log("chulai");
      this.dialogVisible = true;
    },
    // 删除
    async deleteFn(row) {
      console.log(row);
      try {
        await this.$modal.confirm("你确定要删除吗");
        let { msg, code } = await getVoucherRatioStatusApi({ id: row.idStr });
        if (code == 200) {
          this.$modal.msgSuccess(msg);
          this.getVoucherRatioListFn();
        }
      } catch (error) {
        this.$modal.msg("已取消");
      }

      // console.log(result);
    },
    // 关闭新增发放对话框
    closeFn() {
      this.dialogVisible = false;
    },
    // 修改函数
    async editFn(row) {
      this.dialogVisible = true;
      this.$refs.AddAndEdit.getDetailFn(row);
    },
    // row每一行的数据，去发放详细
    async clickLook(row) {
      this.$router.push({ path: "/fnancialPlatform/AGR/AGR-detail" });
    },
  },
};
</script>

<style lang ="scss" scoped>
.comform {
  margin-top: 20px;
}
</style>